home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 18 / CU Amiga Magazine's Super CD-ROM 18 (1997)(EMAP Images)(GB)[!][issue 1998-01].iso / CUCD / Programming / AmigaE / Src / Rkrm / Graphics_Libraries / Primitives / usercopperexample.e < prev    next >
Encoding:
Text File  |  1995-09-20  |  4.6 KB  |  136 lines

  1. -> UserCopperExample.e - User Copper List Example
  2.  
  3. ->>> Header (globals)
  4. OPT PREPROCESS
  5.  
  6. MODULE 'dos/dos',
  7.        'exec/memory',
  8.        'graphics/copper',
  9.        'graphics/gfxmacros',
  10.        'graphics/text',
  11.        'graphics/videocontrol',
  12.        'graphics/view',
  13.        'hardware/custom',
  14.        'intuition/intuition',
  15.        'intuition/preferences',
  16.        'intuition/screens'
  17.  
  18. ENUM ERR_NONE, ERR_KICK, ERR_SCRN, ERR_WIN
  19.  
  20. RAISE ERR_KICK IF KickVersion()=FALSE,
  21.       ERR_SCRN IF OpenScreenTagList()=NIL,
  22.       ERR_WIN  IF OpenWindowTagList()=NIL,
  23.       "MEM"    IF AllocMem()=NIL
  24.  
  25. DEF screen=NIL:PTR TO screen, window=NIL:PTR TO window,
  26.     -> E-Note: set-up custom
  27.     custom=CUSTOMADDR:PTR TO custom
  28. ->>>
  29.  
  30. ->>> PROC main()
  31. PROC main() HANDLE
  32.   DEF ret_val=RETURN_OK, viewPort:PTR TO viewport
  33.   -> Open a screen and a window
  34.   openAll()
  35.   -> Create and attach the user Copper list.
  36.   loadCopper()
  37.   -> Wait until the user clicks in the close gadget.
  38.   REPEAT
  39.   UNTIL WaitIMessage(window)=IDCMP_CLOSEWINDOW
  40. EXCEPT DO
  41.   IF window
  42.     viewPort:=ViewPortAddress(window)
  43.     IF viewPort.ucopins
  44.       -> Free the memory allocated for the Copper list.
  45.       FreeVPortCopLists(viewPort)
  46.       RemakeDisplay()
  47.     ENDIF
  48.     CloseWindow(window)
  49.   ENDIF
  50.   IF screen THEN CloseScreen(screen)
  51.   SELECT exception
  52.   CASE ERR_KICK;  WriteF('Error: requires V37\n')
  53.                   ret_val:=ERROR_INVALID_RESIDENT_LIBRARY
  54.   CASE ERR_SCRN;  WriteF('Error: failed to open screen\n')
  55.                   ret_val:=ERROR_NO_FREE_STORE
  56.   CASE ERR_WIN;   WriteF('Error: failed to open window\n')
  57.                   ret_val:=ERROR_NO_FREE_STORE
  58.   CASE "MEM";     WriteF('Error: ran out of memory\n')
  59.                   ret_val:=ERROR_NO_FREE_STORE
  60.   ENDSELECT
  61. ENDPROC ret_val
  62. ->>>
  63.  
  64. ->>> PROC openAll()
  65. CONST MY_WA_WIDTH=270  -> Width of window.
  66.  
  67. -> Opens screen and window
  68. -> E-Note: any exception raised here will be handled by the caller
  69. PROC openAll()
  70.   KickVersion(37)
  71.   screen:=OpenScreenTagList(NIL,
  72.                            [SA_OVERSCAN, OSCAN_STANDARD,
  73.                             SA_TITLE,    'User Copper List Example',
  74.                             SA_FONT, ['topaz.font', TOPAZ_SIXTY, 0, 0]:textattr,
  75.                             NIL])
  76.   -> E-Note: C version uses obsolete tags, and in fact used an IDCMP flag,
  77.   ->         INACTIVEWINDOW, with WA_FLAGS (I guess they meant WFLG_ACTIVATE)
  78.   window:=OpenWindowTagList(NIL,
  79.                            [WA_CUSTOMSCREEN, screen,
  80.                             WA_TITLE,        '<- Click here to quit.',
  81.                             WA_IDCMP,        IDCMP_CLOSEWINDOW,
  82.                             WA_FLAGS,        WFLG_DRAGBAR OR WFLG_CLOSEGADGET OR
  83.                                              WFLG_ACTIVATE,
  84.                             WA_LEFT,         (screen.width-MY_WA_WIDTH)/2,
  85.                             WA_TOP,          screen.height/2,
  86.                             WA_HEIGHT,       screen.font.ysize+3,
  87.                             WA_WIDTH,        MY_WA_WIDTH,
  88.                             NIL])
  89. ENDPROC
  90. ->>>
  91.  
  92. ->>> PROC loadCopper()
  93. CONST NUMCOLORS=32
  94.  
  95. -> Creates a Copper list program and adds it to the system
  96. -> E-Note: again, any exception raised here will be handled by the caller
  97. PROC loadCopper()
  98.   DEF i, scanlines_per_color, viewPort:PTR TO viewport, uCopList,
  99.       spectrum:PTR TO INT
  100.   -> Allocate memory for the Copper list.
  101.   -> Make certain that the initial memory is cleared.
  102.   -> E-Note: we *have* to use AllocMem() since FreeVPortCopLists() is used
  103.   uCopList:=AllocMem(SIZEOF ucoplist, MEMF_PUBLIC OR MEMF_CLEAR)
  104.  
  105.   -> Initialise the Copper list buffer.
  106.   CINIT(uCopList, NUMCOLORS)
  107.  
  108.   scanlines_per_color:=screen.height/NUMCOLORS
  109.  
  110.   spectrum:=[$0604, $0605, $0606, $0607, $0617, $0618, $0619, $0629,
  111.              $072a, $073b, $074b, $074c, $075d, $076e, $077e, $088f,
  112.              $07af, $06cf, $05ff, $04fb, $04f7, $03f3, $07f2, $0bf1,
  113.              $0ff0, $0fc0, $0ea0, $0e80, $0e60, $0d40, $0d20, $0d00]:INT
  114.   -> Load in each color.
  115.   FOR i:=0 TO NUMCOLORS-1
  116.     CWAIT(uCopList, i*scanlines_per_color, 0)
  117.     -> E-Note: hard to use CMOVE() due to use of {}, which CMOVEA() eliminates
  118.     -> E-Note: use the offset constant COLOR plus n*SIZEOF INT for n-th color
  119.     CMOVEA(uCopList, CUSTOMADDR+COLOR+0, spectrum[i])
  120.   ENDFOR
  121.  
  122.   CEND(uCopList)  -> End the Copper list.
  123.  
  124.   viewPort:=ViewPortAddress(window)  -> Get a pointer to the ViewPort.
  125.   Forbid()  -> Forbid task switching while changing the Copper list.
  126.   viewPort.ucopins:=uCopList
  127.   Permit()  -> Permit task switching again.
  128.  
  129.   -> Enable user Copper list clipping this ViewPort.
  130.   VideoControl(viewPort.colormap, [VTAG_USERCLIP_SET, NIL, NIL])
  131.  
  132.   RethinkDisplay()  -> Display the new Copper list.
  133. ENDPROC
  134. ->>>
  135.  
  136.